#include "NetflixDataElement.h"
#include <sstream>
#include <iostream>

using namespace std;

NetflixDataElement::NetflixDataElement(string title, vector<string> directors, vector<string> cast,
	vector<string> genres, vector<UserComment> userComments, double netflixRating, int movieId) : _title(title), _directors(directors), _cast(cast), 
	_genres(genres), _userComments(userComments), _netflixRating(netflixRating), _movieId(movieId) {

		if(genres.size() > 0) {
			this->_mainGenre = genres[genres.size()-1];
			parseCategory(_mainGenre);
		}
}

NetflixDataElement::NetflixDataElement(string title, double netflixRating, int movieId) : _title(title), _netflixRating(netflixRating), _movieId(movieId) {

}

CATEGORY& NetflixDataElement::getCategory() {
	return _category;
}

void NetflixDataElement::getAvgSentimentFromComments(float& posSentiment, float& negSentiment) {
	float sentiment = 0;

	float pSentiment = 0;
	int numPos = 0;

	float nSentiment = 0;
	int numNeg = 0;

	for(size_t c = 0; c < _userComments.size(); c++) {
		UserComment comment = _userComments[c];
		float tempSent = comment.AvgEmotion();
		if(tempSent < 0) {
			nSentiment+= tempSent;
			numNeg++;
		}
		else {
			pSentiment+=tempSent;
			numPos++;
		}
	}

	if(numPos > 0) {
		posSentiment = pSentiment / numPos;
	}

	if(numNeg > 0) {
		negSentiment = nSentiment / numNeg;
	}
}

CATEGORY NetflixDataElement::parseCategory(std::string mainGenre) {

	if(mainGenre == "Action & Adventure") {
		_category = ACTION;
	}
	else if(mainGenre == "Horror") {
		_category = HORROR;
	}
	else if(mainGenre == "Classic") {
		_category = CLASSIC;
	}
	else if(mainGenre == "Comedy") {
		_category = COMEDY;
	}
	else if(mainGenre == "Documentaries") {
		_category = DOCUMENTARIES;
	}
	else if(mainGenre == "Music") {
		_category = MUSIC;
	}
	else if(mainGenre == "Kids") {
		_category = KIDS;
	}
	else if(mainGenre == "Romance") {
		_category = ROMANCE;
	}
	else if(mainGenre == "TV Shows") {
		_category = TV_SHOWS;
	}
	else if(mainGenre == "Dramas") {
		_category = DRAMAS;
	}
	else if(mainGenre == "Thrillers") {
		_category = THRILLERS;
	}
	return _category;
}

int NetflixDataElement::getMovieId() {
	return _movieId;
}

std::string& NetflixDataElement::getMainGenre() {
	return _mainGenre;
}

void NetflixDataElement::setMainGenre(string mainGenre) {
	this->_mainGenre = mainGenre;
}

vector<UserComment>& NetflixDataElement::getUserComments() {
	return _userComments;
}

NetflixDataElement::NetflixDataElement(void)
{
}


NetflixDataElement::~NetflixDataElement(void)
{
}
